<?php
/**
Version 0.1
SEMF - Web Desiging Framework for Sport Event Managment
Copyright (C) 2006, SEMF Developers

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
$container_id =$_GET['container'];
$page_xml = $_GET['page_xml'];


if(!isset($semf_root) )
{
	$semf_root = '../';
	// Define that we are returning XML content & not to cache:
	header('Content-Type: text/xml');
	header('Cache-control: no-cache');
}


if ( file_exists($page_xml) && strlen(file_get_contents($page_xml)) > 0)
{
	// load the xml
	$doc = new DOMDocument();
	$doc->load($page_xml);
	$doc->validate();
	
	$container = NULL;
	$component = NULL;
	$component_name = NULL;
	if ( !isset($container_id) || $container_id==NULL || 
							$container_id == 'null') //this come from js  
	{
		$container = $doc->documentElement;
		//$component_name = 'Container'; //this is the root container..
	}
	else
	{
		$container = $doc->getElementById($container_id);
		//$component_name = $container->tagName;
	}
	
	//this is what we are going to parse..
	$the_component = $container->firstChild;

	$xslt_file = "containers_extract.xsl";
	
	
	$xml_str = $doc->saveXML($the_component);
	$doc2 = new DOMDocument();
	$doc2 ->loadXML( $xml_str);
	
	$xslt = new xsltProcessor;
	$xslt->importStyleSheet(DomDocument::load($xslt_file));
	
	/** two steps was followed to eliminate transfeering xml headers */
	$final =  $xslt->transformToDoc($doc2);
	echo $final->saveXML($final->documentElement);
}


?>
